<?php
/**
 * Funkcja do wyświetlania imagów
 */
function smarty_function_MFImage($param, &$smarty) {
	
	
	//przekazywanie parametrów do wyświetlania w request
	if(isset($param['request'])) {
		
		$attr = array();
		
		if(isset($_REQUEST[$param['request']])) {
			$path = $_REQUEST[$param['request']];
			$attr['src'] = "src=\"$path\"";			
		}elseif(isset($param['altImg'])){
			$path = $param['altImg'];
			$attr['src'] = "src=\"$path\"";
		}
		
		$alt = isset($param['alt'])?$param['alt']:"";
		$attr['alt'] = "alt=\"$alt\"";
		
		$title = isset($param['title'])?$param['title']:"";
		$attr['title'] = "title=\"$title\"";
		
		if(isset($param['id'])) {
			$id = $param['id'];
			$attr['id'] = "id=\"$id\"";
		}
		
		if(isset($param['class'])) {
			$class = $param['class'];
			$attr['class'] = "class=\"$class\"";
		}
		
		if(isset($param['border'])) {
			$border = $param['border'];
			$attr['border'] = "border=\"$border\"";
		}
		
		if(isset($attr['src'])) {
			$attrStr = implode(" ",$attr);
			return "<img $attrStr />";
		}
	}
	
	if(isset($param['avatar'])) {
		$user = $param['avatar'];
		$size = isset($param['size'])?$param['size']:2;
		$alt = $title = $user->getLogin();
		
		$image = $user->getAvatar($size);
		$path = URL_STATIC_CONTENT . '/upload/image/avatar/'.$image->getPath();
		$path2 = PATH_STATIC_CONTENT . '/upload/image/avatar/'.$image->getPath();
		if(!file_exists($path2)) {
			switch($size) {
				case '1':
					$path = URL_STATIC_CONTENT . '/upload/image/avatar/profil1.gif';
					break;
				case '2':
					$path = URL_STATIC_CONTENT . '/upload/image/avatar/profil2.gif';
					break;
				case '3':
					$path = URL_STATIC_CONTENT . '/upload/image/avatar/profil3.gif';
					break;
				default:
			}
		}
		$id = isset($param['id'])?$param['id']:'';
		
		$attr['src'] = "src=\"$path\"";
		$attr['border'] = "border=\"0\"";
		$attr['alt'] = "alt=\"$alt\"";
		$attr['title'] = "title=\"$title\"";
		//$attr['id'] = "id=\"$id\"";
		
		$class = isset($param['class'])?' '.$param['class']:'';
		
		$attr['class'] = "class=\"avatar_all$class\"";
		
		$attrStr = implode(" ",$attr);
		return "<img $attrStr />";
		
	}
	
	if(isset($param['defaultAvatar'])) {
		$size = isset($param['size'])?$param['size']:2;
		$res = ImageDAL::GetResult(array('id_image_group' => 1, 'size' => $size));
		$image = $res[0];
		
		$alt = $title = 'Avatar';
		
		$path = URL_STATIC_CONTENT . '/upload/image/avatar/'.$image->getPath();
		
		$attr['src'] = "src=\"$path\"";
		$attr['border'] = "border=\"0\"";
		$attr['alt'] = "alt=\"$alt\"";
		$attr['title'] = "title=\"$title\"";
	
		$attrStr = implode(" ",$attr);
		return "<img $attrStr />";
		
	}
}